/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package isd.inventario.rn;

import isd.general.excepciones.ExcepcionGeneralSistema;
import isd.general.modelo.GR_ComprobantePK;
import isd.inventario.dao.ComprobanteInventarioDAO;
import isd.inventario.modelo.ST_Comprobante;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author Claudio
 */
@Stateless
public class ComprobanteInventarioRN {

    @EJB private ComprobanteInventarioDAO comprobanteDAO;


    public Integer getProximoNumeroComprobante(String modfor,String codfor){

        Integer proxNumero;
        Integer ultNumero = comprobanteDAO.getUltimoNumeroComprobante(modfor, codfor);

        if(ultNumero==null) proxNumero = 1;
        else proxNumero = ultNumero + 1;

        return proxNumero;

    }

    public ST_Comprobante getComprobante(GR_ComprobantePK idPK) throws ExcepcionGeneralSistema{

        ST_Comprobante cs = comprobanteDAO.getComprobante(idPK);
        if(cs==null) throw new ExcepcionGeneralSistema("No se encontró comprobante de stock ("+idPK.getCodcom()+")");
        return cs;
    }

    public ST_Comprobante getComprobante(String modcom, String codcom) throws ExcepcionGeneralSistema{

        ST_Comprobante cs = comprobanteDAO.getComprobante(new GR_ComprobantePK(modcom, codcom));
        if(cs==null) throw new ExcepcionGeneralSistema("No se encontró comprobante de stock ("+codcom+")");
        return cs;
    }

    public List<ST_Comprobante> getLista() {

        return comprobanteDAO.getLista();
    }






    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
 
}
